package com.test.fileapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import butterknife.BindView;

import android.os.Bundle;
import android.widget.LinearLayout;

import com.test.fileapplication.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
//    @BindView(R.id.actMainContainer)
    public LinearLayout actMainContainer;
    private List<BaseFragment> fragments = new ArrayList<>();
    private FileFragment storageFragment;
    private BaseFragment mContent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        storageFragment = new FileFragment();
        fragments.add(storageFragment);
        switchFragment(null, storageFragment);
    }

    private void switchFragment(BaseFragment from, BaseFragment to) {
        if (from != to) {
            mContent = to;
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            if (!to.isAdded()) {
                if (from != null) {
                    ft.hide(from);
                }
                if (to != null) {
                    ft.add(R.id.actMainContainer, to).commit();
                }
            } else {
                if (from != null) {
                    ft.hide(from);
                }
                if (to != null) {
                    ft.show(to).commit();
                }
            }
        }
    }
}
